    package com.sxt.service.impl;

import com.github.pagehelper.Page;
import com.sxt.common.DataGridView;
import com.sxt.domain.Bills;
import com.sxt.domain.Billstype;
import com.sxt.mapper.BillstypeMapper;
import com.sxt.service.BillstypeService;
import com.sxt.vo.BillsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.sxt.mapper.BillsMapper;
import com.sxt.service.BillsService;

import java.util.List;

@Service
public class BillsServiceImpl implements BillsService{

    @Resource  //jdk的注解   从IOC里面取值 默认根据对象类型和接口类型的名字找对象
    private BillsMapper billsMapper;

    @Autowired //spring的注解  从IOC里面取值  默认根据类型找
    private BillstypeMapper  billstypeMapper;

    @Autowired
    private BillstypeService billstypeService;


    @Override
    public DataGridView queryAllBills(BillsVo billsVo) {
        Page<Object> page=new Page<>(billsVo.getPage(),billsVo.getLimit());
        List<Bills> bills = this.billsMapper.queryAllBills(billsVo);
        for (Bills bill : bills) {
            Billstype billstype=this.billstypeService.selectById(bill.getTypeid());
            bill.setTypename(billstype.getName());
        }
        return new DataGridView(page.getTotal(),bills);
    }
//    @Override
//    public DataGridView queryAllBills(BillsVo billsVo) {
//        Page<Object> page=new Page<>(billsVo.getPage(),billsVo.getLimit());
//        List<Bills> bills = this.billsMapper.queryAllBills(billsVo);
//        for (Bills bill : bills) {
//            Billstype billstype=this.billstypeMapper.selectById(bill.getTypeid());
//            bill.setTypename(billstype.getName());
//        }
//        return new DataGridView(page.getTotal(),bills);
//    }

    @Override
    public void addBills(Bills bills) {
        this.billsMapper.addBills(bills);
    }
}
